'use strict';

const Controller = require('egg').Controller;
const { getLotteryRes } = require("../../utils/Tools");
const lotteryConf = require("../../config/lottery.json");

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, lottery server';
  }

  /**
   * 获取抽奖相关配置 奖品，每次抽奖消耗多少钱
   */
  async lotteryConfig() {
    this.ctx.body = {
      code: 0,
      msg: 'success',
      data: {
        lottery: lotteryConf['lottery'],
        point_cost: lotteryConf['point_cost'],
        diamond: lotteryConf['diamond']
      }
    };
  }

  // 获取抽奖结果
  async getLotteryRes() {
    const resKey = getLotteryRes(lotteryConf['prisze'], 'prop');
    if (!resKey) {
      return this.ctx.body = {
        code: 1,
        msg: 'error',
        data: null,
      };
    }
    this.ctx.body = {
      code: 0,
      msg: 'success',
      data: resKey,
    };
  }
}

module.exports = HomeController;
